home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / smail-3.1.28 / pd / pathalias / local.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-03  |  1.6 KB  |  89 lines

  1. /* Smail SCCS ID: @(#)pd/pathalias/local.c    1.2 %G 00:43:26 */
  2. /* pathalias -- by steve bellovin, as told to peter honeyman */
  3. #ifndef lint
  4. static char    *sccsid = "@(#)local.c    9.2 88/06/10";
  5. #endif /* lint */
  6.  
  7. #include <stdio.h>
  8. #include "config.h"
  9.  
  10. #ifdef    UNAME
  11. #include <sys/utsname.h>
  12.  
  13. char    *
  14. local()
  15. {
  16.     static struct utsname utsname;
  17.     extern int uname();
  18.  
  19.     (void) uname(&utsname);
  20.     return(utsname.nodename);
  21. }
  22.  
  23. #else /* !UNAME */
  24.  
  25. char    *
  26. local()
  27. {
  28.     static char lname[64];
  29.     extern int gethostname();
  30.  
  31.     (void) gethostname(lname, (int) sizeof(lname));
  32.     lname[sizeof(lname)] = 0;
  33.     return(lname);
  34. }
  35.  
  36. #ifndef GETHOSTNAME
  37.  
  38. STATIC int
  39. gethostname(name, len)
  40.     char *name;
  41.     int len;
  42. {    FILE *whoami;
  43.     char *ptr;
  44.     extern int pclose();
  45.     extern FILE *fopen(), *popen();
  46.  
  47.     *name = '\0';
  48.  
  49.     /* try /etc/whoami */
  50.     if ((whoami = fopen("/etc/whoami", "r")) != 0) {
  51.         (void) fgets(name, len, whoami);
  52.         (void) fclose(whoami);
  53.         if ((ptr = index(name, '\n')) != 0)
  54.             *ptr = '\0';
  55.     }
  56.     if (*name)
  57.         return 0;
  58.  
  59.     /* try /usr/include/whoami.h */
  60.     if ((whoami = fopen("/usr/include/whoami.h", "r")) != 0) {
  61.         while (!feof(whoami)) {
  62.             char    buf[100];
  63.  
  64.             if (fgets(buf, 100, whoami) == 0)
  65.                 break;
  66.             if (sscanf(buf, "#define sysname \"%[^\"]\"", name))
  67.                 break;
  68.         }
  69.         (void) fclose(whoami);
  70.         if (*name)
  71.             return 0;
  72.     }
  73.  
  74.     /* ask uucp */
  75.     if ((whoami = popen("uuname -l", "r")) != 0) {
  76.         (void) fgets(name, len, whoami);
  77.         (void) pclose(whoami);
  78.         if ((ptr = index(name, '\n')) != 0)
  79.             *ptr = '\0';
  80.     }
  81.     if (*name)
  82.         return 0;
  83.     
  84.     /* aw hell, i give up!  is this really unix? */
  85.     return -1;
  86. }
  87. #endif /* GETHOSTNAME */
  88. #endif /* UNAME */
  89.